import java.io.*;
import java.util.*;

public class Main {
	String input;
	StringTokenizer st;
	BufferedReader br;
	StringBuilder sb;
	
	int n;
	int[][] bomb;
	boolean checked;
	
	public Main() {
		br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder();
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.beginProcess();
	}

	void beginProcess() {
		int k,
		    i,
	        j;
		try {
			while((input = br.readLine()) != null) {
				st = new StringTokenizer(input);
				n = Integer.parseInt(st.nextToken());
				for(k = 0; k < n; k++) {
					bomb = new int[8][8];
					for(i = 0; i < bomb.length; i++) {
						st = new StringTokenizer(br.readLine());
						for(j = 0; j < bomb.length; j++)
							bomb[i][j] = Integer.parseInt(st.nextToken());
					}
					if(k != n - 1) br.readLine();
					
					checked = true;
					bombCheck();
					
					if(checked) sb.append("O\n");
					else sb.append("X\n");
				}
			}
			System.out.print(sb);
		}
		catch(Exception ex) {
			System.err.println(ex.toString());
		}
	}
	
	void bombCheck() {
		int i,
            j,
            k,
            tmpI,
            tmpJ;
		for(i = 0; i < bomb.length; i++)
			for(j = 0; j < bomb.length; j++)
				if(bomb[i][j] == 1) {
					for(k = 0; k < bomb.length; k++)
						if(k != i)
							if(bomb[k][j] == 1) checked = false;
					for(k = 0; k < bomb.length; k++)
						if(k != j)
							if(bomb[i][k] == 1) checked = false;
					tmpI = i;
					tmpJ = j;
					while((tmpI - 1) >= 0 && (tmpI - 1) < bomb.length &&
						  (tmpJ - 1) >= 0 && (tmpJ - 1) < bomb.length) {
						tmpI -= 1;
						tmpJ -= 1;
					}
					while(tmpI >= 0 && tmpI < bomb.length &&
						  tmpJ >= 0 && tmpJ < bomb.length) {
						if(tmpI != i && tmpJ != j)
							if(bomb[tmpI][tmpJ] == 1) checked = false;
						tmpI += 1;
						tmpJ += 1;
					}
					tmpI = i;
					tmpJ = j;
					while((tmpI - 1) >= 0 && (tmpI - 1) < bomb.length &&
						  (tmpJ + 1) >= 0 && (tmpJ + 1) < bomb.length) {
						tmpI -= 1;
						tmpJ += 1;
					}
					while(tmpI >= 0 && tmpI < bomb.length &&
						  tmpJ >= 0 && tmpJ < bomb.length) {
						if(tmpI != i && tmpJ != j)
							if(bomb[tmpI][tmpJ] == 1) checked = false;
						tmpI += 1;
						tmpJ -= 1;
					}
				}
	}
	
}